<template>
	<view class="ayi-page tab-page">
		<navigation :isBack="false" title="充值提现"><text @click="toReport('2')" class="nav-right-radius" slot="string">明细</text></navigation>
		<view class="recharge-money" @click="toWalletPage()">
			<view class="recharge-item-i icon-left"><i class="iconfont" style="color:#59aaff;">&#xe63b;</i></view>
			<view class="recharge-item-i content">
				<span class="i-strong">账户余额</span>
				<span class="i-strong">{{ money }}元</span>
			</view>
			<view class="recharge-item-i icon-right"><i class="iconfont" style="color: #c0c0c0; font-size: 48rpx;">&#xe61b;</i></view>
		</view>
		<view class="recharge-item" v-if="menuData.zhcz == '1'" @click="toAccountrecharge()">
			<view class="recharge-item-i icon-left"><i class="iconfont" style="color: #54d4b6;">&#xe613;</i></view>
			<view class="recharge-item-i content">
				<span class="i-title">账户充值</span>
				<span>多种充值方式可选</span>
				<span>银行卡,支付宝,财付通,微信支付</span>
			</view>
			<view class="recharge-item-i icon-right"><i class="iconfont" style="color: #c0c0c0; font-size: 48rpx;">&#xe61b;</i></view>
		</view>
		<view class="recharge-item" v-if="menuData.tx == '1'" @click="toWithdraw()">
			<view class="recharge-item-i icon-left"><i class="iconfont" style="color: #f5770a; position: absolute; left: 16rpx; top: -24rpx;">&#xe616;</i></view>
			<view class="recharge-item-i content">
				<span class="i-title">提现</span>
				<span>多种提现方式可选</span>
				<span>银行卡,支付宝,财付通,微信支付</span>
			</view>
			<view class="recharge-item-i icon-right"><i class="iconfont" style="color: #c0c0c0; font-size: 48rpx;">&#xe61b;</i></view>
		</view>
		<view class="recharge-item" v-if="menuData.czjl == '1'" @click="toReport('1')">
			<view class="recharge-item-i icon-left"><image class="img-img" mode="aspectFit" src="/static/img/icon/recharge.png"></image></view>
			<view class="recharge-item-i content">
				<span class="i-title">充值记录</span>
				<span>查询充值,提现交易记录</span>
				<span>交易明细</span>
			</view>
			<view class="recharge-item-i icon-right"><i class="iconfont" style="color: #c0c0c0; font-size: 48rpx;">&#xe61b;</i></view>
		</view>
		<view class="recharge-item" v-if="isThird" @click="toQuotaPage()">
			<view class="recharge-item-i icon-left"><i class="iconfont" style="color: #eb30da;">&#xe647;</i></view>
			<view class="recharge-item-i content">
				<span class="i-title">额度转化</span>
				<span>真人游戏，体育竞技及电子竞技等，游戏金额转换</span>
			</view>
			<view class="recharge-item-i icon-right"><i class="iconfont" style="color: #c0c0c0; font-size: 48rpx;">&#xe61b;</i></view>
		</view>
	</view>
</template>

<script>
import { Tools, Config, URL, Net, VueTools } from '@/common/tools.js';
import navigation from '@/components/navigation.vue';
import Tabbar from '@/components/tabbar.vue';
export default {
	components: {
		Tabbar,
		navigation
	},
	data() {
		return {
			menuData: { zhcz: '', tx: '', czjl: '' }, //菜单是否隐藏的对象
			isThird: false, //是否有第三方
			money: '0.00' //默认的总的金额
		};
	},
	onLoad() {
		this.isThird = Config.is3rd;
		this.showTotalMoney();
		this.showMenu();
	},
	methods: {
		/**
		 * 入口是否被隐藏处理
		 */
		showMenu() {
			let that = this;
			Net.ayiHttp(
				URL.FILE_RECHARGEWITHDRAWAL,
				'{}',
				function(res) {
					if (res.code == Config.SUCCESS_CODE) {
						//成功的逻辑
						let data = Tools.aesDecodeToJson(res.data);
						console.log('提现充值加载的入口文件', data);
						that.menuData = data;
					} else if (res.code == Config.FAIL_CODE) {
						VueTools.toastNo(res.message);
					} else if (res.code == Config.LOGIN_CODE) {
						uni.navigateTo({
							url: '/pages/my/login/login'
						});
					}
				},
				function(err) {
					console.log('error:', err);
				}
			);
		},
		/**
		 * 充值纪录
		 * @param {Object} typeStr 钱包类型默认获取
		 */
		toReport(typeStr) {
			if (VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == 1 || VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == '1') {
				this.$store.commit('isTestPlay');
				if (this.$store.state.isTestPlay) {
					VueTools.toastNo('试玩账号不能进入');
					return;
				} else {
					if (typeStr == '1') {
						let param = '{"name":"1","type":"1"}';
						this.navigateToSigleUrl('/pages/recharge/transaction/transaction?p=' + Tools.paramAESEncrypt(param));
					} else if (typeStr == '2') {
						let param = '{"name":"2","type":"2"}';
						this.navigateToSigleUrl('/pages/recharge/transaction/transaction?p=' + Tools.paramAESEncrypt(param));
					}
				}
			} else {
				this.navigateToSigleUrl('/pages/my/login/login');
			}
		},
		/**
		 * 账户充值
		 */
		toAccountrecharge() {
			if (VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == 1 || VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == '1') {
				this.$store.commit('isTestPlay');
				if (this.$store.state.isTestPlay) {
					VueTools.toastNo('试玩账号不能进入');
					return;
				} else {
					this.navigateToSigleUrl('/pages/recharge/accountrecharge/accountrecharge');
				}
			} else {
				this.navigateToSigleUrl('/pages/my/login/login');
			}
		},
		/**
		 * 提现
		 */
		toWithdraw() {
			let that = this;
			if (VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == 1 || VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == '1') {
				this.$store.commit('isTestPlay');
				if (this.$store.state.isTestPlay) {
					VueTools.toastNo('试玩账号不能进入');
					return;
				} else {
					Net.ayiHttp(
						URL.USER_SHOWACCTOUT,
						'{"username":"' + this.username + '","password":"' + this.psw + '"}',
						function(res) {
							if (res.code == Config.SUCCESS_CODE) {
								//成功的逻辑
								let tt = Tools.aesDecodeToJson(res.data);
								if (!Tools.isEmpty(tt.outcashmsg)) {
									if (tt.reason == 'cash') {
										uni.showModal({
											title: '万漉会提示',
											content: tt.outcashmsg,
											showCancel: false,
											confirmText: '确定'
										});
										return;
									}
									uni.showModal({
										title: '万漉会提示',
										content: tt.outcashmsg,
										confirmText: '确定',
										cancelText: '取消',
										success: function(res) {
											if (res.confirm) {
												that.navigateToSigleUrl('/pages/my/personalcenter/personalcenter');
											}
										}
									});
									return;
								}
								that.navigateToSigleUrl('/pages/recharge/withdraw/withdraw');
							} else if (res.code == Config.FAIL_CODE) {
								VueTools.toastNo(res.message);
							} else if (res.code == Config.LOGIN_CODE) {
								uni.navigateTo({
									url: '/pages/my/login/login'
								});
							}
						},
						function(err) {
							console.log('error:', err);
						}
					);
				}
			} else {
				this.navigateToSigleUrl('/pages/my/login/login');
			}
		},
		/**
		 * 额度转化
		 */
		toQuotaPage() {
			if (VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == 1 || VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == '1') {
				this.$store.commit('isTestPlay');
				if (this.$store.state.isTestPlay) {
					VueTools.toastNo('试玩账号不能进入');
					return;
				} else {
					this.navigateToSigleUrl('/pages/recharge/quota/quota');
				}
			} else {
				this.navigateToSigleUrl('/pages/my/login/login');
			}
		},
		/**
		 * 钱包的数据
		 */
		toWalletPage(){
			if (VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == 1 || VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY) == '1') {
				this.$store.commit('isTestPlay');
				if (this.$store.state.isTestPlay) {
					VueTools.toastNo('试玩账号不能进入');
					return;
				} else {
					this.navigateToSigleUrl('/pages/my/wallet/wallet');
				}
			} else {
				this.navigateToSigleUrl('/pages/my/login/login');
			}
		},
		showTotalMoney() {
			let that = this;
			let tempMoney = VueTools.getStorageSync(Config.MONEY_KEY);
			if (!Tools.isEmpty(tempMoney)) {
				let temp = tempMoney;
				that.money = Tools.keepTwoDecimal(temp.credit2);
				return;
			}
			Net.ayiHttp(
				URL.USER_FINDCREDIT,
				'{}',
				function(res) {
					if (res.code == Config.SUCCESS_CODE) {
						//成功的逻辑
						let data = Tools.aesDecodeToJson(res.data);
						that.money = Tools.keepTwoDecimal(data.credit2);
						VueTools.setStorageSync(Config.MONEY_KEY, data);
					} else if (res.code == Config.FAIL_CODE) {
						VueTools.toastNo(res.message);
					} else if (res.code == Config.LOGIN_CODE) {
						uni.navigateTo({
							url: '/pages/my/login/login'
						});
					}
				},
				function(err) {
					console.log('error:', err);
				}
			);
		}
	},
	onUnload() {},
	onTabItemTap(option) {
		if (this.$store.state.tabbar_now_index != 3 || this.$store.state.tabbar_now_index != '3') {
			// #ifdef APP-PLUS
			this.Tab.getInstance().show();
			// #endif
			this.$store.commit('setTabbarIndex', option.index);
			uni.$emit('clearMenuTimer');
			uni.$emit('isClearTimeOut', { isClear: true });
			let isLogin = VueTools.getStorageSync(Config.IS_LOGIN_STORE_KEY);
			if (!Tools.isEmpty(isLogin) && (isLogin == '1' || isLogin == 1)) {
				console.log('需要去登陆recharge');
				return;
			}
		}
	}
};
</script>

<style lang="scss">
.recharge-money {
	height: 210rpx;
}
.recharge-item,
.recharge-money {
	display: flex;
	flex-direction: row;
	align-items: center;
	padding: 0rpx 16rpx;
	border-bottom: 1px solid #e8e9ec;
	.recharge-item-i {
		display: block;
		position: relative;
		padding: 16rpx 0rpx;
	}
	.icon-left {
		flex: 3;
		text-align: center;
		margin-right: 40rpx;
		.iconfont {
			font-size: 80rpx;
		}
		.img-img {
			width: 80rpx;
			height: 80rpx;
		}
	}
	.content {
		flex: 14;
		span.i-title {
			color: #000;
			margin-bottom: 20rpx;
			font-weight: bold;
			font-size: 28rpx;
		}
		span {
			font-size: 20rpx;
			color: #8d8d8d;
			display: block;
		}
		span.i-strong {
			font-size: 34rpx;
			font-weight: 700;
			color: #000;
		}
	}
	.icon-right {
		flex: 1;
	}
}
</style>
